<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * Copyright (C) 2007  Robert Moss
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

class TipMember extends JLClass{
  
  var $id;
  var $project_id;
  var $user_id;
  var $approved;
  var $fav_team;
  var $champ_tip;
  var $slogan;
  var $reminder;
  var $receipt;
  var $picture;
  var $last_tip;
  
  function TipMember( &$db ) {
		$this->mosDBTable( '#__joomleague_tip_members', 'id', $db );
	}
  
  function approve( $cid=null, $post=null, $publish=1 ) {
		if (!is_array( $cid ) || count( $cid ) < 1) {
			$this->_error = "No items selected.";
			return false;
		}
		
		$cids = implode( ',', $cid );
		
		$this->_db->setQuery( "UPDATE $this->_tbl SET approved='$publish'"
		. "\nWHERE id IN ($cids)"
		);
    
		if (!$this->_db->query()) {
			$this->_error = $this->_db->getErrorMsg();
			return false;
		}
		
		$this->_error = '';
		return true;
	}
	
  function deleteUserTips( $cid=null, $post, $tips=0 ) {
      if (!is_array( $cid ) || count( $cid ) < 1) {
         $this->_error = "No items selected.";
         return false;
      }
      $query = '';
      if ($post['project_id']) $query = ' AND (`project_id`='.$post['project_id'].')';
      $query .= ';';
      foreach($cid as $cids) {
         $this->_db->setQuery("SELECT user_id FROM $this->_tbl WHERE (`id`=".$cids.");");
         $registered = $this->_db->loadResult();
   
         if($registered){
   
            
               $this->_db->setQuery("DELETE FROM #__joomleague_tip_results WHERE (`user_id`=".$registered.")".$query);
               $this->_db->query_batch(false);
            
            $this->_db->setQuery("DELETE FROM $this->_tbl WHERE (`id`=".$cids.");");
            if (!$this->_db->query()) {
               $this->_error = $this->_db->getErrorMsg();
               return false;
            }
         }
      }
      return true;
  }
	
  
}

?>
